package boardgamer.yavalath.common;

import java.io.Serializable;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * @author garysoed
 */
public class YavalathGameSetting implements Serializable {

  private static final long serialVersionUID = -8171249270968161251L;
  public static final YavalathGameSetting DEFAULT
      = new YavalathGameSetting(BoardSize.NORMAL, Rule.LOSE_3_WIN_4);
  
  private final Rule rule;
  private final BoardSize boardSize;

  public YavalathGameSetting(BoardSize boardSize, Rule rule) {
    this.boardSize = checkNotNull(boardSize, "boardSize");
    this.rule = checkNotNull(rule, "rule");
  }

  public Rule getRule() {
    return rule;
  }

  public BoardSize getBoardSize() {
    return boardSize;
  }

  public enum Rule implements Serializable {
    LOSE_3_WIN_4(3, 4, "Lose with 3 tiles, win with 4 tiles"),
    LOSE_4_WIN_5(4, 5, "Lose with 4 tiles, win with 5 tiles");
    
    private final int loseLength;
    private final int winLength;
    private final String renderedText;

    private Rule(int loseLength, int winLength, String renderedText) {
      this.loseLength = loseLength;
      this.winLength = winLength;
      this.renderedText = checkNotNull(renderedText, "renderedText");
    }

    public int getLoseLength() {
      return loseLength;
    }

    public int getWinLength() {
      return winLength;
    }
    
    public String render() {
      return renderedText;
    }
  }
  
  public enum BoardSize implements Serializable {
    SMALL(4, "4x4x4"),
    NORMAL(5, "5x5x5"),
    LARGE(6, "6x6x6");
    
    private final int size;
    private final String renderedText;
    
    private BoardSize(int size, String renderedText) {
      this.size = size;
      this.renderedText = checkNotNull(renderedText, "renderedText");
    }
    
    public int getSize() {
      return size;
    }
    
    public String render() {
      return renderedText;
    }
  }
}
